import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 动态路由规则
export const asyncRouter = [
  // 组织架构
  {
    path: '/departments',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/departments/departments.vue'),
      meta: { title: '组织架构', icon: 'tree' }
    }]
  },
  // 员工管理
  {
    path: '/employees',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/employees/employees.vue'),
      meta: { title: '员工管理', icon: 'people' }
    }]
  }
  // // 公司设置
  // {
  //   path: '/settings',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/settings/settings.vue'),
  //     meta: { title: '公司设置', icon: 'el-icon-s-tools' }
  //   }]
  // },
  // // 工资管理
  // {
  //   path: '/salarys',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/salarys/salarys.vue'),
  //     meta: { title: '工资管理', icon: 'el-icon-loading' }
  //   }]
  // },
  // // 社保管理
  // {
  //   path: '/social_securitys',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/social_securitys/social_securitys.vue'),
  //     meta: { title: '社保管理', icon: 'el-icon-menu' }
  //   }]
  // },
  // // 考勤管理
  // {
  //   path: '/attendances',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/attendances/attendances.vue'),
  //     meta: { title: '考勤管理', icon: 'el-icon-date' }
  //   }]
  // },
  // // 审批管理
  // {
  //   path: '/approvals',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/approvals/approvals.vue'),
  //     meta: { title: '审批管理', icon: 'el-icon-loading' }
  //   }]
  // },
  // // 权限管理
  // {
  //   path: '/permissions',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/permissions/permissions.vue'),
  //     meta: { title: '权限管理', icon: 'el-icon-s-tools' }
  //   }]
  // }
]
// 静态路由规则
export const constantRoutes = [
  // 登录页
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 404报错
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRouter]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
